﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Medical.Business;
using Medical.Entity;

/// <summary>
/// 有问必答
/// </summary>
public partial class Faq : WebPage
{
    /// <summary>
    /// 分类ID
    /// </summary>
    protected int nSortID = 0;
    protected int nPageIndex = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["page"] != null)
            {
                nPageIndex = Convert.ToInt32(Request.QueryString["page"]);
            }
            InitData();
        }
    }

    /// <summary>
    /// 数据初化
    /// </summary>
    protected void InitData()
    {
        anpPage.EnableUrlRewriting = true;
        anpPage.UrlRewritePattern = @"~/faq/?page={0}";
        if (RouteData.Values["urlname"] != null)
        {
            string strUrlName = RouteData.Values["urlname"].ToString();
            BisSortInfo bisSortInfo = new BisSortInfo();
            DataTable dtSort = bisSortInfo.GetSortInfo(strUrlName);
            //   ltlPageUrl.Text = "<a href=\"/faq/\" target=\"_blank\" title=\"有问必答\">有问必答</a> &gt; ";
            if (dtSort != null && dtSort.Rows.Count > 0)
            {
                nSortID = Convert.ToInt32(dtSort.Rows[0]["ID"]);
                if (dtSort.Rows[0]["PID"].ToString() != string.Empty)
                {
                    //  faqsortlist.Visible = false;
                    ltlSortName.Text += "<a href=\"/faq/" + dtSort.Rows[0]["PPageUrlName"].ToString() + "/\" title=\"" + dtSort.Rows[0]["PName"].ToString() + "\" target=\"_blank\">" + Server.HtmlEncode(dtSort.Rows[0]["PName"].ToString()) + "</a> &gt; ";
                }
                else
                {

                }
                ltlSortName.Text += Server.HtmlEncode(dtSort.Rows[0]["Name"].ToString());
                anpPage.UrlRewritePattern = @"~/faq/" + strUrlName + "/?page={0}";
                string strPageTitle = string.IsNullOrEmpty(dtSort.Rows[0]["PageTitle"].ToString()) ? (dtSort.Rows[0]["Name"].ToString() + "_" + strWebTitle) : dtSort.Rows[0]["PageTitle"].ToString();
                SetPageInfo(strPageTitle, dtSort.Rows[0]["PageKeywords"].ToString(), dtSort.Rows[0]["PageDescription"].ToString());
            }
            else
            {
                Response.Redirect("/404.html");
            }
        }
        else
        {
            ltlSortName.Text = "最新问题";
            DataRow[] drList = Until.GetSEO().Select("Type=7");
            if (drList.Length > 0)
                SetPageInfo(drList[0]["PageTitle"].ToString() == string.Empty ? ("专家答疑_" + strWebTitle) : drList[0]["PageTitle"].ToString(), drList[0]["PageKeywords"].ToString(), drList[0]["PageDescription"].ToString());
        }
        InitList();
        InitList();
    }

    /// <summary>
    /// 获取列表
    /// </summary>
    protected void InitList()
    {
        int nRecordCount = 0;
        int nPageCount = 0;
        DataTable dtFaq = new BisFeedBack().GetFeedBackList(nSortID, 0, true, string.Empty, 0, string.Empty, string.Empty, nPageIndex, anpPage.PageSize, ref nPageCount, ref nRecordCount);
        anpPage.RecordCount = nRecordCount;
        if (nRecordCount == 0)
            noData.Visible = true;
        else
            noData.Visible = false;
        rptFaq.DataSource = dtFaq;
        rptFaq.DataBind();
        dtFaq.Dispose();
    }
}